package com.ev.asl.service.impl;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.ev.asl.vo.*;
import com.ev.asl.vo.voBillOfPush.CheckOutVO;
import com.ev.framework.utils.HttpClientUtils;
import com.ev.framework.utils.ShiroUtils;
import com.ev.framework.utils.StringUtils;
import com.ev.asl.config.ApiParam;
import com.ev.asl.config.JiateConstant;
import com.ev.asl.config.KisApiUrlParam;
import com.ev.asl.service.KisBillOfPushService;
import com.ev.asl.vo.voBillOfPush.PurchaseBlueOrRedVO;
import com.ev.scm.domain.StockInDO;
import com.ev.scm.domain.StockInItemDO;
import com.ev.scm.domain.StockOutDO;
import com.ev.scm.domain.StockOutItemDO;
import com.ev.system.dao.UserDao;
import com.ev.system.domain.UserDO;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.lang3.tuple.Pair;
import org.apache.commons.lang3.tuple.Triple;
import org.apache.http.client.methods.HttpGet;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;
import org.springframework.util.ObjectUtils;

import java.io.UnsupportedEncodingException;
import java.net.URLEncoder;
import java.util.*;
import java.util.stream.Collectors;

@Slf4j
@Service
public class KisBillOfPushServiceImpl implements KisBillOfPushService {

    @Value("${kisurl.authorityCode}")
    private String authorityCode;
    @Autowired
    private KisApiUrlParam kisApiUrlParam;
    @Autowired
    private UserDao userDao;


    /**
     * 推送统一接口
     * @param apiParamPushVo
     * @return
     */
    public Triple<Boolean, String,ApiResultVOS> pushBusinessDocuments(ApiParamPushVo apiParamPushVo) {
        String result = HttpClientUtils.sendJsonStr(kisApiUrlParam.getUrl_push_bill(), JSONObject.toJSONString(apiParamPushVo));
        String msg = "同步出现异常，请稍后重试！";
        if (StringUtils.isNotBlank(result)) {
            Object parse = JSON.parse(result);
            ApiResultVOS apiResultVOS = JSON.parseObject(parse.toString(), ApiResultVOS.class);
            if (Objects.nonNull(apiResultVOS)) {
                //{"status":0,"msg":"过程或函数 'PROC_1K_StockBill11' 需要参数 '@UserId'，但未提供该参数。","data":""}
                //"status":0 同步成功但处理数据发成异常 date为空
                //status":1 同步失败  date为空
                if (Objects.equals(apiResultVOS.getStatus(), JiateConstant.ZERO)) {
                    //成功
                    return Triple.of(true, apiResultVOS.getMsg(),apiResultVOS);
                }else{
                    //异常
                    return Triple.of(false, apiResultVOS.getMsg(),null);
                }
            }
        }
        return Triple.of(false, msg ,null);
    }
    /**
     * 获取token接口
     */
    @Override
    public Triple<Boolean, String,ApiResultVO2S> getK3Token() {
        String url = null;
        log.info("---------------开始获取token接口" );
        try {
            // 字符数据最好encoding以下;这样一来，某些特殊字符才能传过去(如:某人的名字就是“&”,不encoding的话,传不过去)
            log.info("---------------authorityCode："+ this.authorityCode);
            url = kisApiUrlParam.getUrl_get_token() + "?authorityCode=" + URLEncoder.encode(this.authorityCode, "utf-8");
            log.info("---------------url："+ url);
        } catch (UnsupportedEncodingException e1) {
            e1.printStackTrace();
        }
        String result = HttpClientUtils.sendJsonStr(url, null);
        ApiResultVO2S resultVO2S = JSON.parseObject(result, ApiResultVO2S.class);
        log.info("--------11111-------resultVO2S："+ resultVO2S);
        if (ObjectUtils.isEmpty(resultVO2S)){
            return Triple.of(false, "请求获取token接口接口没有得到result" ,null);
        }
        if (ObjectUtils.isEmpty(resultVO2S.getStatusCode()) || !resultVO2S.getStatusCode().equals(200)){
            return Triple.of(false, resultVO2S.getMessage() ,null);
        }
        return Triple.of(true, resultVO2S.getMessage() ,resultVO2S);
    }


//    public static void main(String[] args) {
//        HashMap<String, Object> map = new HashMap<>();
//        HashMap<String, String> map2 = new HashMap<>();
//        map2.put("FBillNo","234");
//        map2.put("FChecker","5234");
//        map2.put("FCheckDirection","2");
//        map2.put("FDealComment","");
//        map.put("Data",map2);
//        String toString = map.toString();
//        String string = JSONObject.toJSONString(map);
//        String string2 = JSONObject.toJSONString(toString);
//        System.out.println(string);
//    }
    /**
     * 审核生产领料
     */
    @Override
    public Triple<Boolean, String, ApiResultVO2S> checkK3LinLiao(String token, String FBillNo, String FChecker, boolean tryAgain) {
        if (ObjectUtils.isEmpty(token) || !tryAgain) {
            Triple<Boolean, String, ApiResultVO2S> k3Token = getK3Token();
            if (!k3Token.getLeft()){
                return Triple.of(false, k3Token.getMiddle() ,null);
            }
            token = k3Token.getRight().getData().getToken();
            log.info("------111111---------获取到token："+ token);
            ShiroUtils.getUser().setToken(token);
        };
        FChecker = "吴江海";
        HashMap<String, Object> map = new HashMap<>();
        HashMap<String, String> map2 = new HashMap<>();
        map2.put("FBillNo",FBillNo);
        map2.put("FChecker",FChecker);
        map2.put("FCheckDirection","1");
        map2.put("FDealComment","");
        map.put("Data",map2);
        String url = null;
        log.info("-------checkK3LinLiao  2222--------开始审批生产领料接口" );
        try {
            // 字符数据最好encoding以下;这样一来，某些特殊字符才能传过去(如:某人的名字就是“&”,不encoding的话,传不过去)
            url = kisApiUrlParam.getUrl_check_lingliao() + "?token=" + URLEncoder.encode(token, "utf-8");
        } catch (UnsupportedEncodingException e1) {
            e1.printStackTrace();
        }
        log.info("------2222---------map："+ JSONObject.toJSONString(map));
        String result = HttpClientUtils.sendJsonStr(url, JSONObject.toJSONString(map));
        ApiResultVO2S resultVO2S = JSON.parseObject(result, ApiResultVO2S.class);
        log.info("-------3333--------resultVO2S："+ resultVO2S);
        if (ObjectUtils.isEmpty(resultVO2S)){
            return Triple.of(false, "审批销售生产领料接口没有得到result" ,null);
        }
        if (ObjectUtils.isEmpty(resultVO2S.getStatusCode()) || !resultVO2S.getStatusCode().equals(200)){
            if (tryAgain){
                return checkK3LinLiao(token, FBillNo, FChecker,  false);
            }else {
                return Triple.of(false, resultVO2S.getMessage() ,null);
            }
        }
        map2.put("FCheckDirection","2");
        String result2 = HttpClientUtils.sendJsonStr(url, JSONObject.toJSONString(map));
        ApiResultVO2S resultVO2S2 = JSON.parseObject(result2, ApiResultVO2S.class);
        if (ObjectUtils.isEmpty(resultVO2S2)){
            return Triple.of(false, "审批销售生产领料接口没有得到result" ,null);
        }
        if (ObjectUtils.isEmpty(resultVO2S2.getStatusCode()) || !resultVO2S2.getStatusCode().equals(200)){
            if (tryAgain){
                return checkK3LinLiao(token, FBillNo, FChecker,  false);
            }else {
                return Triple.of(false, resultVO2S2.getMessage() ,null);
            }
        }
        return Triple.of(true, resultVO2S2.getMessage() ,resultVO2S);
    }
    /**
     * 审核生产领料：不启动审核
     */
    @Override
    public Triple<Boolean, String, ApiResultVO2S> checkK3LinLiao2(String token, String FBillNo, String FChecker, boolean tryAgain) {
        if (ObjectUtils.isEmpty(token) || !tryAgain) {
            Triple<Boolean, String, ApiResultVO2S> k3Token = getK3Token();
            if (!k3Token.getLeft()){
                return Triple.of(false, k3Token.getMiddle() ,null);
            }
            token = k3Token.getRight().getData().getToken();
            log.info("------111111---------获取到token："+ token);
            ShiroUtils.getUser().setToken(token);
        };
        FChecker = "吴江海";
        HashMap<String, Object> map = new HashMap<>();
        HashMap<String, String> map2 = new HashMap<>();
        map2.put("FBillNo",FBillNo);
        map2.put("FChecker",FChecker);
        map2.put("FCheckDirection","2");
        map2.put("FDealComment","");
        map.put("Data",map2);
        String url = null;
        log.info("-------checkK3LinLiao2  2222--------开始审批生产领料接口" );
        try {
            // 字符数据最好encoding以下;这样一来，某些特殊字符才能传过去(如:某人的名字就是“&”,不encoding的话,传不过去)
            url = kisApiUrlParam.getUrl_check_lingliao() + "?token=" + URLEncoder.encode(token, "utf-8");
        } catch (UnsupportedEncodingException e1) {
            e1.printStackTrace();
        }
        log.info("------2222---------map："+ JSONObject.toJSONString(map));
        String result = HttpClientUtils.sendJsonStr(url, JSONObject.toJSONString(map));
        ApiResultVO2S resultVO2S = JSON.parseObject(result, ApiResultVO2S.class);
        log.info("-------3333--------resultVO2S："+ resultVO2S);
        if (ObjectUtils.isEmpty(resultVO2S)){
            return Triple.of(false, "审批销售生产领料接口没有得到result" ,null);
        }
        if (ObjectUtils.isEmpty(resultVO2S.getStatusCode()) || !resultVO2S.getStatusCode().equals(200)){
            if (tryAgain){
                return checkK3LinLiao(token, FBillNo, FChecker,  false);
            }else {
                return Triple.of(false, resultVO2S.getMessage() ,null);
            }
        }
//        map2.put("FCheckDirection","2");
//        String result2 = HttpClientUtils.sendJsonStr(url, JSONObject.toJSONString(map));
        return Triple.of(true, resultVO2S.getMessage() ,resultVO2S);
    }
    /**
     * 审核产品入库
     */
    @Override
    public Triple<Boolean, String, ApiResultVO2S> checkK3In(String token, String FBillNo, String FChecker, boolean tryAgain) {
        if (ObjectUtils.isEmpty(token) || !tryAgain) {
            Triple<Boolean, String, ApiResultVO2S> k3Token = getK3Token();
            if (!k3Token.getLeft()){
                return Triple.of(false, k3Token.getMiddle() ,null);
            }
            token = k3Token.getRight().getData().getToken();
            log.info("------111111---------获取到token："+ token);
            ShiroUtils.getUser().setToken(token);
        };
        FChecker = "吴江海";
        HashMap<String, Object> map = new HashMap<>();
        HashMap<String, String> map2 = new HashMap<>();
        map2.put("FBillNo",FBillNo);
        map2.put("FChecker",FChecker);
        map2.put("FCheckDirection","1");
        map2.put("FDealComment","");
        map.put("Data",map2);
        String url = null;
        log.info("-------2222--------开始审批产品入库接口" );
        try {
            // 字符数据最好encoding以下;这样一来，某些特殊字符才能传过去(如:某人的名字就是“&”,不encoding的话,传不过去)
            url = kisApiUrlParam.getUrl_check_ruku() + "?token=" + URLEncoder.encode(token, "utf-8");
        } catch (UnsupportedEncodingException e1) {
            e1.printStackTrace();
        }
        log.info("------2222---------map："+ JSONObject.toJSONString(map));
        String result = HttpClientUtils.sendJsonStr(url, JSONObject.toJSONString(map));
        log.info("------2222.5.5.5.5---------map："+ JSONObject.toJSONString(result));
        ApiResultVO2S resultVO2S = JSON.parseObject(result, ApiResultVO2S.class);
        log.info("-------3333--------resultVO2S："+ resultVO2S);
        if (ObjectUtils.isEmpty(resultVO2S)){
            return Triple.of(false, "审批产品入库接口没有得到result" ,null);
        }
        if (ObjectUtils.isEmpty(resultVO2S.getStatusCode()) || !resultVO2S.getStatusCode().equals(200)){
            if (tryAgain){
                return checkK3In(token, FBillNo, FChecker,  false);
            }else {
                return Triple.of(false, resultVO2S.getMessage() ,null);
            }
        }
        map2.put("FCheckDirection","2");
        String result2 = HttpClientUtils.sendJsonStr(url, JSONObject.toJSONString(map));
        ApiResultVO2S resultVO2S2 = JSON.parseObject(result2, ApiResultVO2S.class);
        if (ObjectUtils.isEmpty(resultVO2S)){
            return Triple.of(false, "审批产品入库接口没有得到result" ,null);
        }
        return Triple.of(true, resultVO2S2.getMessage() ,resultVO2S);

    }
    /**
     * 审核产品入库：不启动审核
     */
    @Override
    public Triple<Boolean, String, ApiResultVO2S> checkK3In2(String token, String FBillNo, String FChecker, boolean tryAgain) {
        if (ObjectUtils.isEmpty(token) || !tryAgain) {
            Triple<Boolean, String, ApiResultVO2S> k3Token = getK3Token();
            if (!k3Token.getLeft()){
                return Triple.of(false, k3Token.getMiddle() ,null);
            }
            token = k3Token.getRight().getData().getToken();
            log.info("------111111---------获取到token："+ token);
            ShiroUtils.getUser().setToken(token);
        };
        FChecker = "吴江海";
        HashMap<String, Object> map = new HashMap<>();
        HashMap<String, String> map2 = new HashMap<>();
        map2.put("FBillNo",FBillNo);
        map2.put("FChecker",FChecker);
        map2.put("FCheckDirection","2");
        map2.put("FDealComment","");
        map.put("Data",map2);
        String url = null;
        log.info("-------2222--------开始审批产品入库接口" );
        try {
            // 字符数据最好encoding以下;这样一来，某些特殊字符才能传过去(如:某人的名字就是“&”,不encoding的话,传不过去)
            url = kisApiUrlParam.getUrl_check_ruku() + "?token=" + URLEncoder.encode(token, "utf-8");
        } catch (UnsupportedEncodingException e1) {
            e1.printStackTrace();
        }
        log.info("------2222---------map："+ JSONObject.toJSONString(map));
        String result = HttpClientUtils.sendJsonStr(url, JSONObject.toJSONString(map));
        ApiResultVO2S resultVO2S = JSON.parseObject(result, ApiResultVO2S.class);
        log.info("-------3333--------resultVO2S："+ resultVO2S);
        if (ObjectUtils.isEmpty(resultVO2S)){
            return Triple.of(false, "审批产品入库接口没有得到result" ,null);
        }
        if (ObjectUtils.isEmpty(resultVO2S.getStatusCode()) || !resultVO2S.getStatusCode().equals(200)){
            if (tryAgain){
                return checkK3In2(token, FBillNo, FChecker,  false);
            }else {
                return Triple.of(false, resultVO2S.getMessage() ,null);
            }
        }
        return Triple.of(true, resultVO2S.getMessage() ,resultVO2S);

    }

    /**
     * @param rob
     * @param type  入库类型
     * @param stockInItemDO 入库主表
     * @param stockInDO 入库子表
     */
    @Override
    public Pair<Boolean, String> inputTypeParamConversionSync(int rob, int type, List<StockInItemDO> stockInItemDO, StockInDO stockInDO) {
        UserDO userDO = userDao.get(ShiroUtils.getUserId());
        //准备参数
        List<PurchaseBlueOrRedVO> billEntry = new ArrayList<>();
        for (StockInItemDO vo : stockInItemDO) {
            PurchaseBlueOrRedVO voOne = new PurchaseBlueOrRedVO();
            voOne.setItemId(vo.getMaterielId().toString());
            voOne.setDCStockId(vo.getWarehouse().toString());
            if (Objects.nonNull(vo.getWarehLocation())) {
                voOne.setDCSPId(vo.getWarehLocation().toString());
            }
            voOne.setBATCHNO(vo.getBatch());
            //主辅单数量  加特 主辅一致
            voOne.setQty(vo.getCount().toString());
            voOne.setSecQty(vo.getCount().toString());
            //TODO     制单人（固定，写死）   需金蝶固定用户后确定
//            voOne.setBillerId(stockInDO.getCreateBy().toString());
            log.info("---------------userDO.getUserId2()：" );
            log.info(JSON.toJSONString(userDO));

            voOne.setBillerId(ObjectUtils.isEmpty(userDO.getUserId2()) ? null : userDO.getUserId2().toString());
            voOne.setUserId(ShiroUtils.getUserId().toString());
            voOne.setFManagerId(stockInDO.getOperator().toString());
            //仓管员  ----操作员
            voOne.setSManagerId(stockInDO.getOperator().toString());
            String interidIntryid = vo.getSourceInteridEntryid() == null ? vo.getInteridEntryid() : vo.getSourceInteridEntryid();
            if (!Objects.equals(interidIntryid.indexOf("-"), -1)) {
                String[] split = interidIntryid.split("-");
                //原单主表主键
                voOne.setSrcInterId(split[0]);
                //金蝶明细行主键
                voOne.setSrcEntryId(split[1]);
            } else {
                //生产计划为单表，无明细行主键   此处不截取
                //原单主表主键
                voOne.setSrcInterId(interidIntryid);
            }
            //源单编码
            voOne.setSrcBillNo(vo.getSourceCode());
            voOne.setSupplyId(ObjectUtils.isEmpty(stockInDO.getSourceCompany()) ? null : stockInDO.getSourceCompany().toString());
            voOne.setGUID(vo.getUuid());
            billEntry.add(voOne);
        }
        ApiParamPushVo apiParamPushVo = ApiParam.paramApiForPushBill(type, billEntry, rob);
        //同步
        log.info("---------------同步参数：" + JSONObject.toJSONString(apiParamPushVo));
        Triple<Boolean, String, ApiResultVOS> resultVOSTriple = this.pushBusinessDocuments(apiParamPushVo);
        String msg = "同步失败";
        //同步成功  ----->  组装 主子主键
        Boolean left = resultVOSTriple.getLeft();
        if (left) {
            try {
                ApiResultVOS right = resultVOSTriple.getRight();
                msg = right.getMsg();
                List<ApiResultOfPushOfMsgVOS> apiResultOfPushOfMsgVOS = JSON.parseArray(msg, ApiResultOfPushOfMsgVOS.class);
                if (!CollectionUtils.isEmpty(apiResultOfPushOfMsgVOS)) {
                    ApiResultOfPushOfMsgVOS msgVOS = apiResultOfPushOfMsgVOS.get(0);
                    stockInDO.setId(Long.parseLong(msgVOS.getInterId()));
                    stockInDO.setInheadCode(msgVOS.getBillNo());
                }
                String datas = right.getDatas();
                List<ApiResultOfPushVOS> callBackResultOfDate = JSON.parseArray(datas, ApiResultOfPushVOS.class);
                if (!CollectionUtils.isEmpty(callBackResultOfDate)) {
                    Long interId = stockInDO.getId();
                    //UUID    FEntryId 行号
                    Map<String, String> fguidAndFEntryId = callBackResultOfDate.stream().collect(Collectors.toMap(ApiResultOfPushVOS::getFGUID, ApiResultOfPushVOS::getFEntryId));
                    stockInItemDO.stream().forEach(aa -> {
                        String uuid = aa.getUuid();
                        if (fguidAndFEntryId.containsKey(uuid)) {
                            String sourceInteridEntryid = interId + "-" + fguidAndFEntryId.get(uuid);
                            aa.setInteridEntryid(sourceInteridEntryid);
                        }
                    });
                    return Pair.of(true, msg);
                } else {
                    return Pair.of(false, msg);
                }
            } catch (Exception e) {
                log.info("---------返回信息解析失败！");
                return Pair.of(false, msg);
            }
        }
        return Pair.of(left, resultVOSTriple.getMiddle());
    }
    /**
     * @param rob
     * @param type  入库类型
     * @param stockInItemDO 入库主表
     * @param stockInDO 入库子表
     */
    @Override
    public Triple<Boolean, String, String> inputTypeParamConversionSync2(int rob, int type, List<StockInItemDO> stockInItemDO, StockInDO stockInDO) {
        UserDO userDO = userDao.get(ShiroUtils.getUserId());
        //准备参数
        List<PurchaseBlueOrRedVO> billEntry = new ArrayList<>();
        for (StockInItemDO vo : stockInItemDO) {
            PurchaseBlueOrRedVO voOne = new PurchaseBlueOrRedVO();
            voOne.setItemId(vo.getMaterielId().toString());
            voOne.setDCStockId(vo.getWarehouse().toString());
            if (Objects.nonNull(vo.getWarehLocation())) {
                voOne.setDCSPId(vo.getWarehLocation().toString());
            }
            voOne.setBATCHNO(vo.getBatch());
            //主辅单数量  加特 主辅一致
            voOne.setQty(vo.getCount().toString());
            voOne.setSecQty(vo.getCount().toString());
            //TODO     制单人（固定，写死）   需金蝶固定用户后确定
//            voOne.setBillerId(stockInDO.getCreateBy().toString());
            log.info("---------------userDO.getUserId2()：" );
            log.info(JSON.toJSONString(userDO));

            voOne.setBillerId(ObjectUtils.isEmpty(userDO.getUserId2()) ? null : userDO.getUserId2().toString());
            voOne.setUserId(ShiroUtils.getUserId().toString());
            voOne.setFManagerId(stockInDO.getOperator().toString());
            //仓管员  ----操作员
            voOne.setSManagerId(stockInDO.getOperator().toString());
            String interidIntryid = vo.getSourceInteridEntryid() == null ? vo.getInteridEntryid() : vo.getSourceInteridEntryid();
            if (!Objects.equals(interidIntryid.indexOf("-"), -1)) {
                String[] split = interidIntryid.split("-");
                //原单主表主键
                voOne.setSrcInterId(split[0]);
                //金蝶明细行主键
                voOne.setSrcEntryId(split[1]);
            } else {
                //生产计划为单表，无明细行主键   此处不截取
                //原单主表主键
                voOne.setSrcInterId(interidIntryid);
            }
            //源单编码
            voOne.setSrcBillNo(vo.getSourceCode());
            voOne.setSupplyId(ObjectUtils.isEmpty(stockInDO.getSourceCompany()) ? null : stockInDO.getSourceCompany().toString());
            voOne.setGUID(vo.getUuid());
            billEntry.add(voOne);
        }
        ApiParamPushVo apiParamPushVo = ApiParam.paramApiForPushBill(type, billEntry, rob);
        //同步
        log.info("---------------同步参数：" + JSONObject.toJSONString(apiParamPushVo));
        Triple<Boolean, String, ApiResultVOS> resultVOSTriple = this.pushBusinessDocuments(apiParamPushVo);
        String msg = "同步失败";
        //同步成功  ----->  组装 主子主键
        Boolean left = resultVOSTriple.getLeft();
        if (left) {
            try {
                ApiResultVOS right = resultVOSTriple.getRight();
                msg = right.getMsg();
                List<ApiResultOfPushOfMsgVOS> apiResultOfPushOfMsgVOS = JSON.parseArray(msg, ApiResultOfPushOfMsgVOS.class);
                if (!CollectionUtils.isEmpty(apiResultOfPushOfMsgVOS)) {
                    ApiResultOfPushOfMsgVOS msgVOS = apiResultOfPushOfMsgVOS.get(0);
                    stockInDO.setId(Long.parseLong(msgVOS.getInterId()));
                    stockInDO.setInheadCode(msgVOS.getBillNo());
                }
                String datas = right.getDatas();
                List<ApiResultOfPushVOS> callBackResultOfDate = JSON.parseArray(datas, ApiResultOfPushVOS.class);
                if (!CollectionUtils.isEmpty(callBackResultOfDate)) {
                    Long interId = stockInDO.getId();
                    //UUID    FEntryId 行号
                    Map<String, String> fguidAndFEntryId = callBackResultOfDate.stream().collect(Collectors.toMap(ApiResultOfPushVOS::getFGUID, ApiResultOfPushVOS::getFEntryId));
                    stockInItemDO.stream().forEach(aa -> {
                        String uuid = aa.getUuid();
                        if (fguidAndFEntryId.containsKey(uuid)) {
                            String sourceInteridEntryid = interId + "-" + fguidAndFEntryId.get(uuid);
                            aa.setInteridEntryid(sourceInteridEntryid);
                        }
                    });
                    return Triple.of(true, msg ,apiResultOfPushOfMsgVOS.get(0).getBillNo());
                } else {
                    return Triple.of(false, msg ,null);
                }
            } catch (Exception e) {
                log.info("---------返回信息解析失败！");
                return Triple.of(false, msg ,null);
            }
        }
        return Triple.of(false, resultVOSTriple.getMiddle() ,null);
    }
    /**
     * @param rob
     * @param type  入库类型
     * @param stockInItemDO 入库主表
     * @param stockInDO 入库子表
     */
    @Override
    public Triple<Boolean, String, String> inputTypeParamConversionSync2(int rob, int type, List<StockInItemDO> stockInItemDO, StockInDO stockInDO, UserDO userDO) {
        //准备参数
        List<PurchaseBlueOrRedVO> billEntry = new ArrayList<>();
        for (StockInItemDO vo : stockInItemDO) {
            PurchaseBlueOrRedVO voOne = new PurchaseBlueOrRedVO();
            voOne.setItemId(vo.getMaterielId().toString());
            voOne.setDCStockId(vo.getWarehouse().toString());
            if (Objects.nonNull(vo.getWarehLocation())) {
                voOne.setDCSPId(vo.getWarehLocation().toString());
            }
            voOne.setBATCHNO(vo.getBatch());
            //主辅单数量  加特 主辅一致
            voOne.setQty(vo.getCount().toString());
            voOne.setSecQty(vo.getCount().toString());
            //TODO     制单人（固定，写死）   需金蝶固定用户后确定
//            voOne.setBillerId(stockInDO.getCreateBy().toString());
            log.info("---------------userDO.getUserId2()：" );
            log.info(JSON.toJSONString(userDO));

            voOne.setBillerId(ObjectUtils.isEmpty(userDO.getUserId2()) ? null : userDO.getUserId2().toString());
            voOne.setUserId(userDO.getUserId().toString());
            voOne.setFManagerId(userDO.getUserId().toString());
            //仓管员  ----操作员
            voOne.setSManagerId(userDO.getUserId().toString());
            String interidIntryid = vo.getSourceInteridEntryid() == null ? vo.getInteridEntryid() : vo.getSourceInteridEntryid();
            if (!Objects.equals(interidIntryid.indexOf("-"), -1)) {
                String[] split = interidIntryid.split("-");
                //原单主表主键
                voOne.setSrcInterId(split[0]);
                //金蝶明细行主键
                voOne.setSrcEntryId(split[1]);
            } else {
                //生产计划为单表，无明细行主键   此处不截取
                //原单主表主键
                voOne.setSrcInterId(interidIntryid);
            }
            //源单编码
            voOne.setSrcBillNo(vo.getSourceCode());
            voOne.setSupplyId(ObjectUtils.isEmpty(stockInDO.getSourceCompany()) ? null : stockInDO.getSourceCompany().toString());
            voOne.setGUID(vo.getUuid());
            billEntry.add(voOne);
        }
        ApiParamPushVo apiParamPushVo = ApiParam.paramApiForPushBill(type, billEntry, rob);
        //同步
        log.info("---------------同步参数：" + JSONObject.toJSONString(apiParamPushVo));
        Triple<Boolean, String, ApiResultVOS> resultVOSTriple = this.pushBusinessDocuments(apiParamPushVo);
        String msg = "同步失败";
        //同步成功  ----->  组装 主子主键
        Boolean left = resultVOSTriple.getLeft();
        if (left) {
            try {
                ApiResultVOS right = resultVOSTriple.getRight();
                msg = right.getMsg();
                List<ApiResultOfPushOfMsgVOS> apiResultOfPushOfMsgVOS = JSON.parseArray(msg, ApiResultOfPushOfMsgVOS.class);
                if (!CollectionUtils.isEmpty(apiResultOfPushOfMsgVOS)) {
                    ApiResultOfPushOfMsgVOS msgVOS = apiResultOfPushOfMsgVOS.get(0);
                    stockInDO.setId(Long.parseLong(msgVOS.getInterId()));
                    stockInDO.setInheadCode(msgVOS.getBillNo());
                }
                String datas = right.getDatas();
                List<ApiResultOfPushVOS> callBackResultOfDate = JSON.parseArray(datas, ApiResultOfPushVOS.class);
                if (!CollectionUtils.isEmpty(callBackResultOfDate)) {
                    Long interId = stockInDO.getId();
                    //UUID    FEntryId 行号
                    Map<String, String> fguidAndFEntryId = callBackResultOfDate.stream().collect(Collectors.toMap(ApiResultOfPushVOS::getFGUID, ApiResultOfPushVOS::getFEntryId));
                    stockInItemDO.stream().forEach(aa -> {
                        String uuid = aa.getUuid();
                        if (fguidAndFEntryId.containsKey(uuid)) {
                            String sourceInteridEntryid = interId + "-" + fguidAndFEntryId.get(uuid);
                            aa.setInteridEntryid(sourceInteridEntryid);
                        }
                    });
                    return Triple.of(true, msg ,apiResultOfPushOfMsgVOS.get(0).getBillNo());
                } else {
                    return Triple.of(false, msg ,null);
                }
            } catch (Exception e) {
                log.info("---------返回信息解析失败！");
                return Triple.of(false, msg ,null);
            }
        }
        return Triple.of(false, resultVOSTriple.getMiddle() ,null);
    }

    /**
     * @param inStockType    入库单据类型
     * @param stockInItemDO  库存子表实体
     * @param stockInDO      库存主表实体
     * @return
     */
    @Override
    public Pair<Boolean, String> masterSwitchForStorageSync(int inStockType, List<StockInItemDO> stockInItemDO, StockInDO stockInDO) {
        switch (inStockType) {
            case 260:
                //采购入库
                //需要返回金蝶保存的主子键 rob -->  蓝字
                return this.inputTypeParamConversionSync(JiateConstant.ROB_BLUE, JiateConstant.OUTSOURCING_WAREHOUSING, stockInItemDO, stockInDO);
            case 182:
                //生产入库     rob -->  蓝字
                return inputTypeParamConversionSync(JiateConstant.ROB_BLUE, JiateConstant.PRODUCTION_STORAGE, stockInItemDO, stockInDO);
            case 199:
                //生产退料     rob -->  红字
                return inputTypeParamConversionSync(JiateConstant.ROB_RED,JiateConstant.PRODUCTION_MATERIAL_REQUISITION, stockInItemDO, stockInDO);
            case 261:
                //销售退货     rob -->  红字
                return inputTypeParamConversionSync(JiateConstant.ROB_RED,JiateConstant.SALES_OUTBOUND, stockInItemDO, stockInDO);
            default:
                break;
        }
        return Pair.of(true,"无此单据类型！建议核对对接方案！");
    }

    @Override
    public Pair<Boolean, String> masterSwitchForOutboundSync(int outStockType, List<StockOutItemDO> stockOutItemDO, StockOutDO stockOutDO) {
        switch (outStockType) {
            case 259:
                //采购退货    rob -->  红字
                return this.outTypeParamConversionSync(JiateConstant.ROB_RED, JiateConstant.OUTSOURCING_WAREHOUSING, stockOutItemDO, stockOutDO);
            case 193:
                //生产领用 （领用出库）     rob -->  蓝字
                return outTypeParamConversionSync(JiateConstant.ROB_BLUE, JiateConstant.PRODUCTION_MATERIAL_REQUISITION, stockOutItemDO, stockOutDO);
            case 188:
                //销售出库     rob -->  蓝字
                return outTypeParamConversionSync(JiateConstant.ROB_BLUE,JiateConstant.SALES_OUTBOUND, stockOutItemDO, stockOutDO);
//            case 3333:
//                //其他出库     rob -->  蓝字   OtherStockOutApiController
//            case 3333:
//                //委外出库     rob -->  蓝字   OutsourcingStockOutApiController
        }
        return Pair.of(true,"无此单据类型！建议核对对接方案！");
    }

    public Pair<Boolean, String> outTypeParamConversionSync(int rob, int type, List<StockOutItemDO> stockOutItemDO, StockOutDO stockOutDO) {
        UserDO userDO = userDao.get(ShiroUtils.getUserId());
        //准备参数
        List<PurchaseBlueOrRedVO> billEntry = new ArrayList<>();
        for (StockOutItemDO vo : stockOutItemDO) {
            PurchaseBlueOrRedVO voOne = new PurchaseBlueOrRedVO();
            voOne.setItemId(vo.getMaterielId().toString());
            voOne.setDCStockId(vo.getWarehouse().toString());
            if (Objects.nonNull(vo.getWarehLocation())) {
                voOne.setDCSPId(vo.getWarehLocation().toString());
            }
            //TODO  生产批号 修改后为必填，同步会校验
            String batch = vo.getBatch()==null?"2022060608888":vo.getBatch();
            voOne.setBATCHNO(batch);
            //TODO 主单数量 主辅单位一致   辅助单位vo.getCountSub().toString()
            String count = vo.getCount().toString();
            voOne.setQty(count);
//            voOne.setSecQty(vo.getCountSub().toString());
            voOne.setSecQty(count);
            //TODO     制单人（固定，写死）   需金蝶固定用户后确定
            voOne.setBillerId(ObjectUtils.isEmpty(userDO.getUserId2()) ? null : userDO.getUserId2().toString());
            voOne.setUserId(ShiroUtils.getUserId().toString());
//            voOne.setBillerId(stockOutDO.getCreateBy().toString());
//            voOne.setFManagerId(stockOutDO.getOperator().toString());
            //TODO  仓管员  ----操作员   取当前登录人
            String operator = stockOutDO.getOperator()==null? ShiroUtils.getUserId().toString():stockOutDO.getOperator().toString();
            voOne.setSManagerId(ShiroUtils.getUserId().toString());
            voOne.setFManagerId(ShiroUtils.getUserId().toString());
            String interidIntryid = vo.getSourceInteridEntryid();
            if (!Objects.equals(interidIntryid.indexOf("-"), -1)) {
                String[] split = interidIntryid.split("-");
                //原单主表主键
                voOne.setSrcInterId(split[0]);
                //金蝶明细行主键
                voOne.setSrcEntryId(split[1]);
            } else {
                //生产计划为单表，无明细行主键   此处不截取
                //原单主表主键
                voOne.setSrcInterId(interidIntryid);
            }
            //源单编码
            voOne.setDept("265");//写死 生管科
            voOne.setSrcBillNo(vo.getSourceCode());
            voOne.setConsigneeAdd(stockOutDO.getConsigneeAdd());
            //TODO  多次修改添加的字段  可能和SrcBillNo重复，但不传会报错
            voOne.setFOrderBillNo(vo.getSourceCode());
            //TODO  客户clientId  供应商 supplierId  出库首取客户
            String supplierOrClient = stockOutDO.getClientId()==null? stockOutDO.getSupplierId()==null?"":stockOutDO.getSupplierId().toString():stockOutDO.getClientId().toString();
            if(StringUtils.isNotBlank(supplierOrClient)){
                voOne.setSupplyId(supplierOrClient);
            }
            voOne.setGUID(vo.getUuid());
            billEntry.add(voOne);
        }
        ApiParamPushVo apiParamPushVo = ApiParam.paramApiForPushBill(type, billEntry, rob);
            log.info("-----------出库传参："+JSONObject.toJSONString(apiParamPushVo));
        //同步
        Triple<Boolean, String, ApiResultVOS> resultVOSTriple = this.pushBusinessDocuments(apiParamPushVo);
        String msg = "同步失败";
        //同步成功  ----->  组装 主子主键
        Boolean left = resultVOSTriple.getLeft();
        if (left) {
            try {
                ApiResultVOS right = resultVOSTriple.getRight();
                 msg = right.getMsg();
                List<ApiResultOfPushOfMsgVOS> apiResultOfPushOfMsgVOS = JSON.parseArray(msg, ApiResultOfPushOfMsgVOS.class);
                if (!CollectionUtils.isEmpty(apiResultOfPushOfMsgVOS)) {
                    ApiResultOfPushOfMsgVOS msgVOS = apiResultOfPushOfMsgVOS.get(0);
                    stockOutDO.setId(Long.parseLong(msgVOS.getInterId()));
                    stockOutDO.setOutCode(msgVOS.getBillNo());
                }
                String datas = right.getDatas();
                List<ApiResultOfPushVOS> callBackResult = JSON.parseArray(datas, ApiResultOfPushVOS.class);
                if (!CollectionUtils.isEmpty(callBackResult)) {
                    Long interId = stockOutDO.getId();
                    //UUID    FEntryId 行号
                    Map<String, String> fguidAndFEntryId = callBackResult.stream().collect(Collectors.toMap(ApiResultOfPushVOS::getFGUID, ApiResultOfPushVOS::getFEntryId));
                    stockOutItemDO.stream().forEach(aa -> {
                        String uuid = aa.getUuid();
                        if (fguidAndFEntryId.containsKey(uuid)) {
                            String sourceInteridEntryid = interId + "-" + fguidAndFEntryId.get(uuid);
                            aa.setInteridEntryid(sourceInteridEntryid);
                        }
                    });
                    return Pair.of(true, msg);
                } else {
                    return Pair.of(false, msg);
                }
            } catch (Exception e) {
                log.info("---------返回信息解析失败！");
                return Pair.of(false, msg);
            }
        }
        return Pair.of(left, resultVOSTriple.getMiddle());
    }
    @Override
    public Triple<Boolean, String, String> outTypeParamConversionSync2(int rob, int type, List<StockOutItemDO> stockOutItemDO, StockOutDO stockOutDO) {
        UserDO userDO = userDao.get(ShiroUtils.getUserId());
        //准备参数
        List<PurchaseBlueOrRedVO> billEntry = new ArrayList<>();
        for (StockOutItemDO vo : stockOutItemDO) {
            PurchaseBlueOrRedVO voOne = new PurchaseBlueOrRedVO();
            voOne.setItemId(vo.getMaterielId().toString());
            voOne.setDCStockId(vo.getWarehouse().toString());
            if (Objects.nonNull(vo.getWarehLocation())) {
                voOne.setDCSPId(vo.getWarehLocation().toString());
            }
            //TODO  生产批号 修改后为必填，同步会校验
            String batch = vo.getBatch()==null?"2022060608888":vo.getBatch();
            voOne.setBATCHNO(batch);
            //TODO 主单数量 主辅单位一致   辅助单位vo.getCountSub().toString()
            String count = vo.getCount().toString();
            voOne.setQty(count);
//            voOne.setSecQty(vo.getCountSub().toString());
            voOne.setSecQty(count);
            //TODO     制单人（固定，写死）   需金蝶固定用户后确定
            voOne.setBillerId(ObjectUtils.isEmpty(userDO.getUserId2()) ? null : userDO.getUserId2().toString());
            voOne.setUserId(ShiroUtils.getUserId().toString());
//            voOne.setBillerId(stockOutDO.getCreateBy().toString());
//            voOne.setFManagerId(stockOutDO.getOperator().toString());
            //TODO  仓管员  ----操作员   取当前登录人
            String operator = stockOutDO.getOperator()==null? ShiroUtils.getUserId().toString():stockOutDO.getOperator().toString();
            voOne.setSManagerId(ShiroUtils.getUserId().toString());
            voOne.setFManagerId(ShiroUtils.getUserId().toString());
            String interidIntryid = vo.getSourceInteridEntryid();
            if (!Objects.equals(interidIntryid.indexOf("-"), -1)) {
                String[] split = interidIntryid.split("-");
                //原单主表主键
                voOne.setSrcInterId(split[0]);
                //金蝶明细行主键
                voOne.setSrcEntryId(split[1]);
            } else {
                //生产计划为单表，无明细行主键   此处不截取
                //原单主表主键
                voOne.setSrcInterId(interidIntryid);
            }
            //源单编码
            voOne.setSrcBillNo(vo.getSourceCode());
            //TODO  多次修改添加的字段  可能和SrcBillNo重复，但不传会报错
            voOne.setFOrderBillNo(vo.getSourceCode());
            //TODO  客户clientId  供应商 supplierId  出库首取客户
            String supplierOrClient = stockOutDO.getClientId()==null? stockOutDO.getSupplierId()==null?"":stockOutDO.getSupplierId().toString():stockOutDO.getClientId().toString();
            if(StringUtils.isNotBlank(supplierOrClient)){
                voOne.setSupplyId(supplierOrClient);
            }
            voOne.setGUID(vo.getUuid());
            billEntry.add(voOne);
        }
        ApiParamPushVo apiParamPushVo = ApiParam.paramApiForPushBill(type, billEntry, rob);
            log.info("-----------出库传参："+JSONObject.toJSONString(apiParamPushVo));
        //同步
        Triple<Boolean, String, ApiResultVOS> resultVOSTriple = this.pushBusinessDocuments(apiParamPushVo);
        String msg = "同步失败";
        //同步成功  ----->  组装 主子主键
        Boolean left = resultVOSTriple.getLeft();
        if (left) {
            try {
                ApiResultVOS right = resultVOSTriple.getRight();
                 msg = right.getMsg();
                List<ApiResultOfPushOfMsgVOS> apiResultOfPushOfMsgVOS = JSON.parseArray(msg, ApiResultOfPushOfMsgVOS.class);
                if (!CollectionUtils.isEmpty(apiResultOfPushOfMsgVOS)) {
                    ApiResultOfPushOfMsgVOS msgVOS = apiResultOfPushOfMsgVOS.get(0);
                    stockOutDO.setId(Long.parseLong(msgVOS.getInterId()));
                    stockOutDO.setOutCode(msgVOS.getBillNo());
                }
                String datas = right.getDatas();
                List<ApiResultOfPushVOS> callBackResult = JSON.parseArray(datas, ApiResultOfPushVOS.class);
                if (!CollectionUtils.isEmpty(callBackResult)) {
                    Long interId = stockOutDO.getId();
                    //UUID    FEntryId 行号
                    Map<String, String> fguidAndFEntryId = callBackResult.stream().collect(Collectors.toMap(ApiResultOfPushVOS::getFGUID, ApiResultOfPushVOS::getFEntryId));
                    stockOutItemDO.stream().forEach(aa -> {
                        String uuid = aa.getUuid();
                        if (fguidAndFEntryId.containsKey(uuid)) {
                            String sourceInteridEntryid = interId + "-" + fguidAndFEntryId.get(uuid);
                            aa.setInteridEntryid(sourceInteridEntryid);
                        }
                    });
                    return Triple.of(true, msg ,apiResultOfPushOfMsgVOS.get(0).getBillNo());
                } else {
                    return Triple.of(false, msg ,null);
                }
            } catch (Exception e) {
                log.info("---------返回信息解析失败！");
                return Triple.of(false, msg ,null);
            }
        }
        return Triple.of(false, msg ,null);
    }
    @Override
    public Triple<Boolean, String, String> outTypeParamConversionSync2(int rob, int type, List<StockOutItemDO> stockOutItemDO, StockOutDO stockOutDO, UserDO userDO) {
        //准备参数
        List<PurchaseBlueOrRedVO> billEntry = new ArrayList<>();
        for (StockOutItemDO vo : stockOutItemDO) {
            PurchaseBlueOrRedVO voOne = new PurchaseBlueOrRedVO();
            voOne.setItemId(vo.getMaterielId().toString());
            voOne.setDCStockId(vo.getWarehouse().toString());
            if (Objects.nonNull(vo.getWarehLocation())) {
                voOne.setDCSPId(vo.getWarehLocation().toString());
            }
            //TODO  生产批号 修改后为必填，同步会校验
            String batch = vo.getBatch()==null?"2022060608888":vo.getBatch();
            voOne.setBATCHNO(batch);
            //TODO 主单数量 主辅单位一致   辅助单位vo.getCountSub().toString()
            String count = vo.getCount().toString();
            voOne.setQty(count);
//            voOne.setSecQty(vo.getCountSub().toString());
            voOne.setSecQty(count);
            //TODO     制单人（固定，写死）   需金蝶固定用户后确定
            voOne.setBillerId(ObjectUtils.isEmpty(userDO.getUserId2()) ? null : userDO.getUserId2().toString());
            voOne.setUserId(userDO.getUserId().toString());
//            voOne.setBillerId(stockOutDO.getCreateBy().toString());
//            voOne.setFManagerId(stockOutDO.getOperator().toString());
            //TODO  仓管员  ----操作员   取当前登录人
            String operator = stockOutDO.getOperator()==null? userDO.getUserId().toString():stockOutDO.getOperator().toString();
            voOne.setSManagerId(userDO.getUserId().toString());
            voOne.setFManagerId(userDO.getUserId().toString());
            voOne.setDept("264");//生产科
            String interidIntryid = vo.getSourceInteridEntryid();
            if (!Objects.equals(interidIntryid.indexOf("-"), -1)) {
                String[] split = interidIntryid.split("-");
                //原单主表主键
                voOne.setSrcInterId(split[0]);
                //金蝶明细行主键
                voOne.setSrcEntryId(split[1]);
            } else {
                //生产计划为单表，无明细行主键   此处不截取
                //原单主表主键
                voOne.setSrcInterId(interidIntryid);
            }
            //源单编码
            voOne.setSrcBillNo(vo.getSourceCode());
            //TODO  多次修改添加的字段  可能和SrcBillNo重复，但不传会报错
            voOne.setFOrderBillNo(vo.getSourceCode());
            //TODO  客户clientId  供应商 supplierId  出库首取客户
            String supplierOrClient = stockOutDO.getClientId()==null? stockOutDO.getSupplierId()==null?"":stockOutDO.getSupplierId().toString():stockOutDO.getClientId().toString();
            if(StringUtils.isNotBlank(supplierOrClient)){
                voOne.setSupplyId(supplierOrClient);
            }
            voOne.setGUID(vo.getUuid());
            billEntry.add(voOne);
        }
        ApiParamPushVo apiParamPushVo = ApiParam.paramApiForPushBill(type, billEntry, rob);
            log.info("-----------出库传参："+JSONObject.toJSONString(apiParamPushVo));
        //同步
        Triple<Boolean, String, ApiResultVOS> resultVOSTriple = this.pushBusinessDocuments(apiParamPushVo);
        String msg = "同步失败";
        //同步成功  ----->  组装 主子主键
        Boolean left = resultVOSTriple.getLeft();
        if (left) {
            try {
                ApiResultVOS right = resultVOSTriple.getRight();
                 msg = right.getMsg();
                List<ApiResultOfPushOfMsgVOS> apiResultOfPushOfMsgVOS = JSON.parseArray(msg, ApiResultOfPushOfMsgVOS.class);
                if (!CollectionUtils.isEmpty(apiResultOfPushOfMsgVOS)) {
                    ApiResultOfPushOfMsgVOS msgVOS = apiResultOfPushOfMsgVOS.get(0);
                    stockOutDO.setId(Long.parseLong(msgVOS.getInterId()));
                    stockOutDO.setOutCode(msgVOS.getBillNo());
                }
                String datas = right.getDatas();
                List<ApiResultOfPushVOS> callBackResult = JSON.parseArray(datas, ApiResultOfPushVOS.class);
                if (!CollectionUtils.isEmpty(callBackResult)) {
                    Long interId = stockOutDO.getId();
                    //UUID    FEntryId 行号
                    Map<String, String> fguidAndFEntryId = callBackResult.stream().collect(Collectors.toMap(ApiResultOfPushVOS::getFGUID, ApiResultOfPushVOS::getFEntryId));
                    stockOutItemDO.stream().forEach(aa -> {
                        String uuid = aa.getUuid();
                        if (fguidAndFEntryId.containsKey(uuid)) {
                            String sourceInteridEntryid = interId + "-" + fguidAndFEntryId.get(uuid);
                            aa.setInteridEntryid(sourceInteridEntryid);
                        }
                    });
                    return Triple.of(true, msg ,apiResultOfPushOfMsgVOS.get(0).getBillNo());
                } else {
                    return Triple.of(false, msg ,null);
                }
            } catch (Exception e) {
                log.info("---------返回信息解析失败！");
                return Triple.of(false, msg ,null);
            }
        }
        return Triple.of(false, msg ,null);
    }
    @Override
    public Pair<Boolean, String> allocationParamConversionSync(int rob, int type, List<StockOutItemDO> stockOutItemDO, StockOutDO stockOutDO) {
        UserDO userDO = userDao.get(ShiroUtils.getUserId());
        //准备参数
        List<PurchaseBlueOrRedVO> billEntry = new ArrayList<>();
        for (StockOutItemDO vo : stockOutItemDO) {
            PurchaseBlueOrRedVO voOne = new PurchaseBlueOrRedVO();
            voOne.setItemId(vo.getMaterielId().toString());
            voOne.setDCStockId(vo.getWarehouse().toString());
            voOne.setSCStockId("329");
            voOne.setSCSPId("28");
            if (Objects.nonNull(vo.getWarehLocation())) {
                voOne.setDCSPId(vo.getWarehLocation().toString());
            }
            //TODO  生产批号 修改后为必填，同步会校验
            String batch = vo.getBatch()==null?"2022060608888":vo.getBatch();
            voOne.setBATCHNO(batch);
            //TODO 主单数量 主辅单位一致   辅助单位vo.getCountSub().toString()
            String count = vo.getCount().toString();
            voOne.setQty(count);
//            voOne.setSecQty(vo.getCountSub().toString());
            voOne.setSecQty(count);
            //TODO     制单人（固定，写死）   需金蝶固定用户后确定
            voOne.setBillerId(ObjectUtils.isEmpty(userDO.getUserId2()) ? null : userDO.getUserId2().toString());
            voOne.setUserId(ShiroUtils.getUserId().toString());
//            voOne.setBillerId(stockOutDO.getCreateBy().toString());
//            voOne.setFManagerId(stockOutDO.getOperator().toString());
            //TODO  仓管员  ----操作员   取当前登录人
            String operator = stockOutDO.getOperator()==null? ShiroUtils.getUserId().toString():stockOutDO.getOperator().toString();
            voOne.setSManagerId(ShiroUtils.getUserId().toString());
            voOne.setFManagerId(ShiroUtils.getUserId().toString());
            String interidIntryid = vo.getSourceInteridEntryid();
            if (!Objects.equals(interidIntryid.indexOf("-"), -1)) {
                String[] split = interidIntryid.split("-");
                //原单主表主键
                voOne.setSrcInterId(split[0]);
                //金蝶明细行主键
                voOne.setSrcEntryId(split[1]);
            } else {
                //生产计划为单表，无明细行主键   此处不截取
                //原单主表主键
                voOne.setSrcInterId(interidIntryid);
            }
            //源单编码
            voOne.setSrcBillNo(vo.getSourceCode());
            //TODO  多次修改添加的字段  可能和SrcBillNo重复，但不传会报错
            voOne.setFOrderBillNo(vo.getSourceCode());
            //TODO  客户clientId  供应商 supplierId  出库首取客户
            String supplierOrClient = stockOutDO.getClientId()==null? stockOutDO.getSupplierId()==null?"":stockOutDO.getSupplierId().toString():stockOutDO.getClientId().toString();
            if(StringUtils.isNotBlank(supplierOrClient)){
                voOne.setSupplyId(supplierOrClient);
            }
            voOne.setGUID(vo.getUuid());
            billEntry.add(voOne);
        }
        ApiParamPushVo apiParamPushVo = ApiParam.paramApiForPushBill(type, billEntry, rob);
            log.info("-----------出库传参："+JSONObject.toJSONString(apiParamPushVo));
        //同步
        Triple<Boolean, String, ApiResultVOS> resultVOSTriple = this.pushBusinessDocuments(apiParamPushVo);
        String msg = "同步失败";
        //同步成功  ----->  组装 主子主键
        Boolean left = resultVOSTriple.getLeft();
        if (left) {
            try {
                ApiResultVOS right = resultVOSTriple.getRight();
                 msg = right.getMsg();
                List<ApiResultOfPushOfMsgVOS> apiResultOfPushOfMsgVOS = JSON.parseArray(msg, ApiResultOfPushOfMsgVOS.class);
                if (!CollectionUtils.isEmpty(apiResultOfPushOfMsgVOS)) {
                    ApiResultOfPushOfMsgVOS msgVOS = apiResultOfPushOfMsgVOS.get(0);
                    stockOutDO.setId(Long.parseLong(msgVOS.getInterId()));
                    stockOutDO.setOutCode(msgVOS.getBillNo());
                }
                String datas = right.getDatas();
                List<ApiResultOfPushVOS> callBackResult = JSON.parseArray(datas, ApiResultOfPushVOS.class);
                if (!CollectionUtils.isEmpty(callBackResult)) {
                    Long interId = stockOutDO.getId();
                    //UUID    FEntryId 行号
                    Map<String, String> fguidAndFEntryId = callBackResult.stream().collect(Collectors.toMap(ApiResultOfPushVOS::getFGUID, ApiResultOfPushVOS::getFEntryId));
                    stockOutItemDO.stream().forEach(aa -> {
                        String uuid = aa.getUuid();
                        if (fguidAndFEntryId.containsKey(uuid)) {
                            String sourceInteridEntryid = interId + "-" + fguidAndFEntryId.get(uuid);
                            aa.setInteridEntryid(sourceInteridEntryid);
                        }
                    });
                    return Pair.of(true, msg);
                } else {
                    return Pair.of(false, msg);
                }
            } catch (Exception e) {
                log.info("---------返回信息解析失败！");
                return Pair.of(false, msg);
            }
        }
        return Pair.of(left, resultVOSTriple.getMiddle());
    }


}
